<?php
require_once('../../classes/Student.php');

session_start();

$student = new Student;
$username = mysql_real_escape_string($_POST['username']);
$userpass = mysql_real_escape_string($_POST['password']);
$studentAccount = $student->checkUserAccount($username,$userpass);

if(isset($_POST['log_in']))
{
    if($studentAccount==null){
        header('Location: ../../index.php?action=loginerror=1');   
    }
    else{
        $_SESSION['login'] = 1;
        $find = mysql_query("SELECT user_id FROM account WHERE username = '$username'");
        while($row = mysql_fetch_array($find, MYSQL_ASSOC)){
                $id = $row['user_id'];
            }
        $find = mysql_query("SELECT fname FROM account,userinfo  WHERE account.user_id = '$id' AND userinfo.user_id = '$id'");
        while($row = mysql_fetch_array($find, MYSQL_ASSOC)){
                $_SESSION['fname'] = $row['fname'];
            }
        $find = mysql_query("SELECT lname FROM account,userinfo  WHERE account.user_id = '$id' AND userinfo.user_id = '$id'");
        while($row = mysql_fetch_array($find, MYSQL_ASSOC)){
                $_SESSION['lname'] = $row['lname'];
            }
        $find = mysql_query("SELECT username FROM account,userinfo  WHERE account.user_id = '$id' AND userinfo.user_id = '$id'");
        while($row = mysql_fetch_array($find, MYSQL_ASSOC)){
                $_SESSION['username'] = $row['username'];
            }
        $find = mysql_query("SELECT password FROM account,userinfo  WHERE account.user_id = '$id' AND userinfo.user_id = '$id'");
        while($row = mysql_fetch_array($find, MYSQL_ASSOC)){
                $_SESSION['password'] = $row['password'];
            }
        $find = mysql_query("SELECT gender FROM account,userinfo  WHERE account.user_id = '$id' AND userinfo.user_id = '$id'");
        while($row = mysql_fetch_array($find, MYSQL_ASSOC)){
                $_SESSION['gender'] = $row['gender'];
            }
        echo $_SESSION['fname'].$_SESSION['lname'].$_SESSION['username'].$_SESSION['password'].$_SESSION['gender'];
        header("Location: ../../index.php");
    }
}
?>